/*
* @Author: majingyu
* @Date:   2017-05-24 21:20:09
* @Last Modified by:   jingyu.ma
* @Last Modified time: 2017-08-06 18:50:34
*/

import initialState from '../state';
import { date2time } from 'common/date'

function orderReducer(state = initialState.orders, action){
    switch(action.type){
        //查找订单列表
        case 'SEARCH_ALL_ORDER_BIGIN':
            return Object.assign({}, state, {});
        case 'SEARCH_ALL_ORDER_SUCCESS':
            let orderListNew = state.ordersList.list
            action.data.rows.map(item => {
                orderListNew.push(item);
                item.dtime = date2time(item.dtime);
            })
            return Object.assign({},state,{
                ordersList:{
                    list: orderListNew,
                    pageNo: action.data.currentPageNumber,
                    total: action.data.total
                }
            })
        case 'CHANGE_ORDRT_DETAIL_ID':
            return Object.assign({},state,{
                orderId: action.id
            })
        case 'GET_ORDER_DETAIL_SUCCESS':
            return Object.assign({},state, {
                detail:action.data
            })
        default :
            return state;
    }
}

export default orderReducer;